<template>
	<view class="p-l-20 p-r-20">
		<view class="bg-white p-l-30 p-r-30 m-t-10 br20 p-t-30 p-b-20">
			
			<view class="flex">
				<view class="bold xl m-r-20">
					司机星级
				</view>
				<u-rate 
					:count="5" 
					v-model="star"  
					:min-count="1" 
					active-color="#df563b"
					size="42"
					gutter="20"
					class="m-r-20"
				></u-rate>
				<view class="lg bold" style="color: #A5A5A5;">
					{{isStar(star)}}
				</view>
			</view>
			<view class="flex m-t-20">
				
				<view class="flex-1 ">
					<u-input type="textarea" placeholder="请输入评价内容" v-model="details" ></u-input>
				</view>
			</view>
			<view class="m-t-20">
				<view class="">
					<u-upload ref="uUpload" :show-progress="false" :header="{token: $store.getters.token}"
						:max-count="8" width="150" height="150" :action="action" upload-text="上传图片"
						@on-success="onSuccess"  @on-remove="onRemove" />
				</view>
			</view>
		</view>
		<view class="flex flex-wrap  p-b-20"  >
			<view  :class="{'label-active':item.active}"  class="label-item" v-for="(item,index) in labelList" :key="item.id" @click="check(index)">
				{{item.name}}
			</view>
		</view>
		<view style="padding: 30rpx 20rpx 30rpx 20rpx;" >
			<button type="primary" size="lg" class="br60" @tap="onSubmit">提交申请</button>
		</view>
	</view>
</template>

<script>
	import {getLabel,appraiseAdd} from '@/api/car';
	import {
		mapGetters,
		mapActions
	} from 'vuex'
	import {
		baseURL
	} from '@/config/app'
	export default {
		data() {
			return {
				order_id:null,
				labelList:[],
				details:'',
				star:5,
				file_list:[],
				action: baseURL + '/api/file/formimage',
			}
		},
		onLoad(option) {
			this.order_id = option.id;
			this.getLabelFun();
		},
		methods: {
			onSuccess(e) {
				this.file_list.push(e.data.uri)
			},
			onRemove(index) {
				this.file_list.splice(index, 1)
				console.log(index)
			},
			onSubmit() {
				let label_lists = [];
				this.labelList.forEach((item)=>{
					if(item.active == true){
						label_lists.push(item.id)
					}
				})
				console.log(label_lists)
				let {order_id,file_list,details,star} = this;
				if(star==1 && details==''){
					this.$toast({
						title:'当前评价较低，需要填写评价内容'
					})
					return 
				}
				appraiseAdd({
					order_id,file_list,details,star,label_lists
				}).then().then(res=>{
					if(res.code==1){
						this.$toast({
							title:"评价成功"
						})
						let pages = getCurrentPages(); // 当前页面
						let beforePage = pages[pages.length - 2]; // 上一页
						console.log(beforePage)
						beforePage.$vm.getOrderDetailFun();
						setTimeout(()=>{
							uni.navigateBack({
								
							})
						},1500)
					}
					
				})
				
			},
			check(index) {
				this.labelList[index].active = !this.labelList[index].active
			},
			getLabelFun(){
				getLabel().then(res=>{
					console.log(res)
					let arr = res.data.lists;
					arr.forEach(item=>{
						item.active = false;
					})
					this.labelList = arr.concat();
				})
			}
		},
		computed:{
			
			isStar:function(){
				return function(index){
					if(index==5){
						return '非常好'
					}
					if(index==4){
						return '好'
					}
					if(index==3){
						return '一般'
					}
					if(index==2){
						return '差'
					}
					if(index==1){
						return '非常差'
					}
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.label-active{
		background-color: #df563b !important;
		color: #fff !important;
		border-color: #fff !important;
	}
	.label-item{
		padding: 5upx 10upx;
		border: 1upx solid #999;
		color: #999;
		margin-right: 10upx;
		margin-top: 20upx;
	}
</style>
